<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<%@include file="/fragment/header.jsp"%>
<script type="text/javascript">
	function deleteWbs(url) {
		if (confirm("確定刪除[" + $('#editWbsName').val() + "]?")) {
			return changeAction(url);
		} else {
			return false;
		}

	}
	function changeAction(url) {
		var f = document.getElementById("projMaintainForm");
		f.action = url;
		return true;
	}
	function clearWbsInput() {
		$("#editWbsTypeId").val('');
		$("#editWbsName").val('');
		$("#editEstHr").val('');
		$("#editWbsSn").val('');

	}
	function chooseWbs(sn, name, typeId, estHr) {
		$("#editWbsSn").val(sn);
		$("#editWbsName").val(name);
		$("#editWbsTypeId").val(typeId);
		$("#editEstHr").val(estHr);
	}
	function chooseWbsByAjax(wbsSn) {
		$.ajax({
			type : 'post',
			url : '${pageContext.request.contextPath}/proj/findWbs.do',
			cache : false,
			data : "sn=" + wbsSn,
			success : function(vo) {
				$("#editWbsName").val(vo.name);
				$("#editWbsTypeId").val(vo.typeId);
				$("#editEstHr").val(vo.estHr);
			},
			error : function() {
				alert('Error-"');
			}
		});
	}
</script>
</head>
<body>
    <div id="container">
        <div id="header">
            歡迎, ${user.userName}, <a href="${pageContext.request.contextPath}/logout.do">登出</a>
        </div>
        <%@include file="/fragment/menu.jsp"%>
        你在這&gt;&gt;專案維護&gt;&gt;新增
        <div id="info_msg">
            訊息: <span class="info_msg">${msg }</span>
        </div>
        <form:form method="post" id="projMaintainForm" commandName="projMaintainForm" action="${pageContext.request.contextPath}/proj/initAddProj.do" autocomplete="off">
            <fieldset class="section_title">
                <legend>專案資料</legend>
                <form:hidden path="projSn" />
                名稱:
                <form:input path="projName" readonly="${!projEdited }" />
                系統:
                <input name="textfield2" type="text" size="5" disabled="${!projEdited}" />
                客戶窗口
                <input name="textfield3" type="text" size="10" disabled="${!projEdited}" />
                專案類型: <select name="select" disabled="${!projEdited}">
                    <option>請選擇</option>
                    <option>專案</option>
                    <option>行政</option>
                </select> <br> 描述:
                <form:input path="projDscr" readonly="${!projEdited }" size="100" />
                <br> 預估時數: <br>
                <input type="submit" value="編輯" ${!projEdited?"":"disabled"} class="btn"
                    onclick="javascript: return changeAction('${pageContext.request.contextPath}/proj/editProj.do');" name="edit"
                />
                <input type="submit" value="儲存" ${projEdited?"":"disabled"} class="btn"
                    onclick="javascript: return changeAction('${pageContext.request.contextPath}/proj/saveProj.do');"
                />
                <input type="submit" value="取消" ${projEdited?"":"disabled"} class="btn"
                    onclick="javascript: return changeAction('${pageContext.request.contextPath}/proj/editProj.do');" name="cancel"
                />
                <a href="${pageContext.request.contextPath}/proj/initQueryProj.do"> 返回</a>
            </fieldset>
            <div style="float: left;">
                <fieldset class="section_title">
                    <legend>查詢</legend>
                    <form:input path="searchWbsName" id="selectWbsName" />
                    <form:select path="searchWbsTypeId" id="searchWbsTypeId">
                        <form:option value="">----</form:option>
                        <form:options items="${wbsTypes}" />
                    </form:select>
                    <br />
                    <input type="submit" value="查詢" class="btn"
                        onclick="javascript: return changeAction('${pageContext.request.contextPath}/proj/findWbs.do');"
                    />
                </fieldset>
            </div>
            <div style="float: left;">
                <fieldset class="section_title">
                    <legend>WBS 修改</legend>
                    任務名稱:
                    <form:input path="editWbsName" id="editWbsName" />
                    預估時數:
                    <form:input path="editEstHr" size="4" id="editEstHr" />
                    類型:
                    <form:select path="editWbsTypeId" id="editWbsTypeId">
                        <form:option value="">----</form:option>
                        <form:options items="${wbsTypes}" />
                    </form:select>
                    <form:hidden path="editWbsSn" />
                    <br />
                    <input type="submit" value="新增" class="btn"
                        onclick="return changeAction('${pageContext.request.contextPath}/proj/addWbs.do');"
                    />
                    <input type="submit" value="修改" class="btn"
                        onclick="javascript: return changeAction('${pageContext.request.contextPath}/proj/modifyWbs.do');"
                    />
                    <button type="button" onclick="clearWbsInput();" class="btn">清除</button>
                    <input type="submit" value="刪除" class="btn"
                        onclick="return deleteWbs('${pageContext.request.contextPath}/proj/deleteWbs.do');"
                    />
                </fieldset>
            </div>
            <table style="width: 100%"  border="1">
                <tr class="column_header">
                    <td>操作</td>
                    <td>名稱</td>
                    <td>類型</td>
                    <td>預估時數</td>
                </tr>
                <c:forEach items="${wbsVvoList}" var="data">
                    <tr>
                        <td><input type="radio" name="targetSn" value="${data.sn}"
                                onclick="chooseWbs('${data.sn}','${data.name}','${data.typeId}','${data.estHr}')"
                            /></td>
                        <td>${data.name }</td>
                        <td>${data.typeDscr }</td>
                        <td>${data.estHr }</td>
                    </tr>
                </c:forEach>
            </table>
        </form:form>
        <div id="footer"><%@include file="/fragment/footer.jsp"%>
        </div>
    </div>
</body>
</html>
